package com.woniuxy.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    // 声明交换机
    @Bean
    public DirectExchange exchange() {
        return new DirectExchange("student.exchange");
    }


    // 声明 Redis 删除队列
    @Bean
    public Queue studentDeleteRedisQueue() {
        return new Queue("student.delete.redis.queue");
    }

    // 声明 Elasticsearch 删除队列
    @Bean
    public Queue studentDeleteEsQueue() {
        return new Queue("student.delete.es.queue");
    }

    // 绑定队列到交换机
    @Bean
    public Binding bindingRedis(Queue studentDeleteRedisQueue, DirectExchange exchange) {
        return BindingBuilder
                .bind(studentDeleteRedisQueue)
                .to(exchange)
                .with("student.delete.redis.routingkey");
    }

    @Bean
    public Binding bindingEs(Queue studentDeleteEsQueue, DirectExchange exchange) {
        return BindingBuilder
                .bind(studentDeleteEsQueue)
                .to(exchange)
                .with("student.delete.es.routingkey");
    }
}
